package info.pinlab.pinplayer.model.response;

import info.pinlab.pinplayer.model.task.Task;
import info.pinlab.pinplayer.model.task.TaskInstance;
import info.pinlab.util.HashCodeUtil;



public class ResponseInstance{
	
	private final int attemptN;
	private final int tasksethash;
	private final int taskIx;
	private final int taskhash;		//-- just to be sure
	private final ResponseContent content;
	
	public ResponseInstance(ResponseContent content, int taskSetHash, int taskIx, Task task, int attemptN){
		this.content = content;
		this.tasksethash = taskSetHash;
		this.taskhash = task.hashCode();
		this.taskIx = taskIx;
		this.attemptN = attemptN;
	}
	public ResponseInstance(ResponseInstance respi){
		this.content = respi.content;
		this.taskIx = respi.taskIx;
		this.attemptN = respi.attemptN;
		this.tasksethash = respi.tasksethash;
		this.taskhash = respi.taskhash;
	}
	
	public ResponseInstance(ResponseContent content, TaskInstance taski , int attemptN){
		this(content, taski.getTaskSetHash(), taski.getTaskIx(), taski.getTask(),attemptN);
//		this.content = content;
//		this.tasksethash = taski.getTaskSetHash();
//		this.taskhash = taski.getTask().hashCode();
//		this.taskIx = taski.getTaskIx();
//		this.attemptN = attemptN;
	}
	
	public ResponseContent getResponseContent(){
		return content;
	}
	public int getTaskIx(){
		return taskIx;
	}
	public int getTaskSetHash(){
		return tasksethash;
	}
	
	public int getAttemptN(){
		return attemptN;
	}

	@Override
	public boolean equals(Object obj){
		if(!(obj instanceof ResponseInstance))
				return false;
		ResponseInstance other = (ResponseInstance)obj;
		if(		this.taskIx == other.taskIx 
				&& this.attemptN == other.attemptN
				&& this.tasksethash == other.tasksethash
				&& this.taskhash == other.taskhash
				&& this.content.equals(other.content)){
				return true;
		}
		return false;
	}
	
	@Override
	public int hashCode(){
		int hash = 3006;
		hash = HashCodeUtil.hash(hash, taskIx);
		hash = HashCodeUtil.hash(hash, attemptN);
		hash = HashCodeUtil.hash(hash, tasksethash);
		hash = HashCodeUtil.hash(hash, taskhash);
		hash = HashCodeUtil.hash(hash, content.hashCode());
		return hash;
	}
	
	@Override
	public String toString(){
		return  "Set-"+tasksethash + "_" +  taskIx + "." + attemptN + "_" +  content.getClass().getSimpleName() + "-" + content.hashCode() + " " + content.toString();
	}
	
}

